package bb.lanxing.lib.devices.sprint.entity;

import android.os.Parcel;
import android.os.Parcelable;
import java.math.BigDecimal;

public abstract class SprintDecimal implements Parcelable {
    protected String toBritish;
    protected String toMetric;
    protected int unit;

    @Override
    public int describeContents() {
        return 0;
    }

    public abstract void onBritish();

    public abstract void onMetric();

    public SprintDecimal(SprintDecimal sprintDecimal) {
        this.unit = sprintDecimal.unit;
        this.toMetric = sprintDecimal.toMetric;
        this.toBritish = sprintDecimal.toBritish;
    }

    public SprintDecimal(String str, int i) {
        this(str, i, false, false);
    }

    public SprintDecimal(String str, int i, boolean z, boolean z2) {
        this.unit = i;
        BigDecimal bigDecimal = new BigDecimal(str);
        bigDecimal = z ? bigDecimal.multiply(BigDecimal.TEN) : bigDecimal;
        bigDecimal = z2 ? bigDecimal.divide(BigDecimal.TEN, 4) : bigDecimal;
        String str2 = null;
        this.toMetric = i == 0 ? bigDecimal.toString() : null;
        this.toBritish = i == 1 ? bigDecimal.toString() : str2;
    }

    public SprintDecimal(String str, String str2, boolean z, boolean z2) {
        BigDecimal bigDecimal;
        BigDecimal bigDecimal2;
        if (str != null) {
            float parseFloat = Float.parseFloat(str);
            if (z) {
                bigDecimal2 = new BigDecimal(String.valueOf(parseFloat * 10.0f));
            } else if (z2) {
                bigDecimal2 = new BigDecimal(String.valueOf(parseFloat / 10.0f));
            } else {
                bigDecimal2 = new BigDecimal(parseFloat);
            }
            this.toMetric = bigDecimal2.toString();
        }
        if (str2 != null) {
            float parseFloat2 = Float.parseFloat(str2);
            if (z) {
                bigDecimal = new BigDecimal(parseFloat2 * 10.0f);
            } else if (z2) {
                bigDecimal = new BigDecimal(parseFloat2 / 10.0f);
            } else {
                bigDecimal = new BigDecimal(parseFloat2);
            }
            this.toBritish = bigDecimal.toString();
        }
    }

    public SprintDecimal(Parcel parcel) {
        this.unit = parcel.readInt();
        this.toMetric = parcel.readString();
        this.toBritish = parcel.readString();
    }

    public void setBritish(String str) {
        this.toBritish = str;
    }

    public void setMetric(String str) {
        this.toMetric = str;
    }

    public final SprintDecimal toMetric() {
        if (this.unit != 0 && this.toMetric == null) {
            onMetric();
        }
        return this;
    }

    public final SprintDecimal toBritish() {
        if (this.unit != 1 && this.toBritish == null) {
            onBritish();
        }
        return this;
    }

    public String getValue(int i, boolean z) {
        toMetric();
        toBritish();
        BigDecimal bigDecimal = new BigDecimal(i == 0 ? this.toMetric : this.toBritish);
        if (z) {
            bigDecimal = bigDecimal.multiply(BigDecimal.TEN);
        }
        return bigDecimal.toString();
    }

    public float toFloatValue(int i, boolean z) {
        return new BigDecimal(getValue(i, z)).floatValue();
    }

    public int toIntValue(int i, boolean z) {
        return new BigDecimal(getValue(i, z)).intValue();
    }

    public float toFloatValue(int i) {
        return toFloatValue(i, false);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        SprintDecimal sprintDecimal = (SprintDecimal) obj;
        if (this.unit != sprintDecimal.unit) {
            return false;
        }
        String str = this.toMetric;
        if (str == null ? sprintDecimal.toMetric != null : !str.equals(sprintDecimal.toMetric)) {
            return false;
        }
        String str2 = this.toBritish;
        String str3 = sprintDecimal.toBritish;
        return str2 != null ? str2.equals(str3) : str3 == null;
    }

    public int hashCode() {
        int i = this.unit * 31;
        String str = this.toMetric;
        int i2 = 0;
        int hashCode = (i + (str != null ? str.hashCode() : 0)) * 31;
        String str2 = this.toBritish;
        if (str2 != null) {
            i2 = str2.hashCode();
        }
        return hashCode + i2;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(this.unit);
        parcel.writeString(this.toMetric);
        parcel.writeString(this.toBritish);
    }
}
